package com.liveneo.adapter.mobile.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liveneo.adapter.base.entity.PrpmMobileModel;
import com.liveneo.adapter.base.mapper.PrpmMobileModelMapper;
import com.liveneo.adapter.mobile.service.MobileModelService;
import com.liveneo.adapter.mobile.util.UUIDUtils;

@Service
public class MobileModelServiceImpl implements MobileModelService {
    @Autowired
    private PrpmMobileModelMapper prpmMobileModelMapper;

    @Override
    public PrpmMobileModel getMobileModel(PrpmMobileModel prpmMobileModel) throws Exception {
        return prpmMobileModelMapper.getMobileModel(prpmMobileModel);
    }

    @Override
    public int addMobileModel(PrpmMobileModel prpmMobileModel) throws Exception {
        return prpmMobileModelMapper.addMobileModel(prpmMobileModel);
    }

    @Override
    public int addMobileModelIfNotExist(String phoneModel, String phoneNo, String systemInfo) throws Exception {

        PrpmMobileModel prpmMobileModel = new PrpmMobileModel();
        prpmMobileModel.setPhoneModel(phoneModel);
        prpmMobileModel.setPhoneNo(phoneNo);
        prpmMobileModel.setSystemInfo(systemInfo);
        PrpmMobileModel newPrpmMobileModel = getMobileModel(prpmMobileModel);
        if (null == newPrpmMobileModel) {
            newPrpmMobileModel = new PrpmMobileModel();
            newPrpmMobileModel.setId(UUIDUtils.getUUIDStr());
            newPrpmMobileModel.setCreateTime(new Date());
            newPrpmMobileModel.setPhoneModel(phoneModel);
            newPrpmMobileModel.setPhoneNo(phoneNo);
            newPrpmMobileModel.setSystemInfo(systemInfo);
            return addMobileModel(newPrpmMobileModel);
        }
        return 0;
    }

    @Override
    public List<PrpmMobileModel> queryPre() {
        return this.prpmMobileModelMapper.queryPre();
    }
}
